package com.jch.dm.chapter_1_iterator;

/**
 * @author: jch
 * 书架迭代器类
 **/
public class BookShelfIterator implements Iterator{

    private BookShelf bookShelf;
    private int index;

    public BookShelfIterator(BookShelf bookShelf) {
        this.bookShelf = bookShelf;
        this.index = 0;
    }

    /**
     * 是否存在下一个元素
     *
     * @return 是否存在
     */
    public boolean hasNext() {
        if (index < bookShelf.getLength()){
            return true;
        } else {
            return false;
        }
    }

    /**
     * 下一个元素
     *
     * @return 元素
     */
    public Object next() {
        Book book = bookShelf.getBookAt(index);
        index++;
        return book;
    }
}
